﻿using System.Collections.Generic;
using System.Web.Mvc;

namespace Webbness.Mvc.Validators
{
    public class PhoneNumberValidator : DataAnnotationsModelValidator<PhoneNumberValidatorAttribute>
    {
        public PhoneNumberValidator(ModelMetadata metadata, ControllerContext context, PhoneNumberValidatorAttribute attribute)
            : base(metadata, context, attribute)
        {
        }

        public override IEnumerable<ModelClientValidationRule> GetClientValidationRules()
        {
            return new[] {new ModelClientValidationPhoneRule(ErrorMessage)};
        }
    }

    public class ModelClientValidationPhoneRule : ModelClientValidationRule
    {
        public ModelClientValidationPhoneRule(string errorMessage)
        {
            ErrorMessage = errorMessage;
            ValidationType = "required";
        }
    }
}